<?php
class PsytestForm extends CFormModel {
    public $selectedAnswerId;
    public $answer;

	public function rules() {
		return array(
	//		array('content, name, email', 'required', 'message' => '请填写{attribute}。')
            array('selectedAnswerId', 'required', 'message' => '请选择一个答案。'),
		);
	}

    public function answerAQuestion() {
        if($this->validate()) {
            $this->answer = TestAnswers::model()->with('question', 'question.topic')->findByPk($this->selectedAnswerId);
            $state = $this->answer->question->topic->getState();
            $state[$this->answer->question->questionId] = $this->answer->answerId;
            $this->answer->question->topic->setState($state);
            //print_r($answer->question->topic->getState());
        }
    }

	public function attributeLabels() {
		return array(
		//	'title' => '标题',
		//	'content' => '内容',
		//	'email' => '电子邮件',
		//	'name' => '姓名'
		);
	}
}
